#include "gpio_pwm_thread.h"
#include <iostream>

using std::cout;
using std::endl;

gpio_pwm_thread::gpio_pwm_thread()
{

}

void gpio_pwm_thread::set_pwm_out(bool state)
{
    this->is_pwm_out = state;
}

void gpio_pwm_thread::set_period(qint64 period)
{
    this->period = period;
}

void gpio_pwm_thread::set_duty(qint64 duty)
{
    this->duty = duty;
}

void gpio_pwm_thread::set_pwm_exist(bool state)
{
    this->is_pwm_exist = state;
}

/* run函数 */
void gpio_pwm_thread::run()
{
    this->is_pwm_out = true;

    while(this->is_pwm_exist)
    {
        if(this->is_pwm_out)
        {
            usleep(this->duty/1000);
            emit duty_time_out();
            usleep((this->period-this->duty)/1000);
            emit period_time_out();
        }
        else
        {
            usleep(this->period);
            emit period_time_out();
        }
    }
}
